// pages/myCenter/billing/billing.js
import Common from '../../../common/common.js'
const common = new Common();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    chooseId: 9,
    list:[],
    shwoMask:true,
    phoneList:[
      {id:0,tel:'18856060149',name:'成都区域'}
    ],
    isEnd: false, //是否到底 ,
  },
  
// 切换tab
chooseLit(e) { 
  let chooseId = e.currentTarget.dataset.id;
  this.setData({
    chooseId: chooseId,
  })
  this.init(1,1)
},
// 拨打电话弹框
shwoMask:function(e){
  let no = e.currentTarget.dataset.no;
  if(no==1){
    this.setData({
      shwoMask:false
    })
  }else{
    this.setData({
      shwoMask:true
    })
  }
},
// 点击拨打电话
callphone:function(e){
  wx.makePhoneCall({
    phoneNumber: '010-66100778',
  })
},

// 点击复制物流单号
copyText:function(e){
  let text = e.currentTarget.dataset.text.toString();
  wx.setClipboardData({
    data: text,
    success (res) {
      wx.getClipboardData({
        success (res) {
          
        }
      })
    }
  })
},
// 跳转开票详情
toDetile:function(e){
  let id = e.currentTarget.dataset.id;
  let status = e.currentTarget.dataset.status;
  wx.navigateTo({
    url: '/pages/myCenter/billing/billingDetile/billingDetile?id='+id+'&status='+status,
  })
},
// 初始化数据开票记录列表
init:function(page,type){
  let data={
    "size": 10,
    "current": page,
    "condition": {
      "status":this.data.chooseId,
      "orgSeq":getApp().globalData.orgSeq
    },
    "ascs": [],
    "descs": []
  }
  common.requestAjax('/api/user-service/v1/billingRecord/queryBillingRecord', 'POST', data).then(res => {
    if (res.data.code==1) {
      wx.hideLoading() 
      let list = this.data.list || [];
      let isEnd = this.data.isEnd;
      if (type == 1) {
        //下拉刷新
        list = res.data.records;
        isEnd = false;
      } else if (type == 2) {
        //上拉加载
        list = list.concat(res.data.records);
        if (res.data.records.length == 0) {
          //最后一行没数据 到底了
          isEnd = true;
        }
        setTimeout(() => {
          wx.hideLoading()
        }, 500)
      }
      this.setData({
        list: list,
        isEnd,
      })
    }else{
      common.showToast(res.data.message)
    }
  }).catch(err => {
  })
},
  onLoad: function (options) {

  },
  onShow: function () {
    this.init(1,1);
  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    //清空搜索框
    this.setData({
    
      pageNumber: 1,
    })
    this.init(1, 1)
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 1200)
  },
  

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.isEnd) {
      let page = this.data.page;
      page += 1;
      this.init(page, 2)
      wx.showLoading({
        title: '正在加载中...',
      })
      this.setData({
        page
      })
    }
  },
})